package com.company.dcm.service.Impl;

import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class TaskService {
    private final ConcurrentHashMap<String, Float> progressMap = new ConcurrentHashMap<>();

    public String createTask() {
        String taskId = UUID.randomUUID().toString();
        progressMap.put(taskId, 0.0F);
        return taskId;
    }

    public void updateProgress(String taskId, Float progress) {
        progressMap.put(taskId, progress);
    }

    public Float getProgress(String taskId) {
        return progressMap.getOrDefault(taskId, -1F); // -1表示任务不存在
    }

    public void removeTask(String taskId) {
        progressMap.remove(taskId);
    }
}